package com.cheyun.netsalev3.repository

import com.cheyun.netsalev3.bean.EditDriveParam
import com.cheyun.netsalev3.bean.IsPhoneParam
import com.cheyun.netsalev3.bean.basedata.NormalList
import com.cheyun.netsalev3.bean.drive.ReserveInfo
import com.cheyun.netsalev3.bean.drive.Reservemit
import com.cheyun.netsalev3.bean.login.MemberX
import com.cheyun.netsalev3.utils.CommonFunc
import com.cheyun.netsalev3.utils.CommonFunc.typeToken
import com.cheyun.netsalev3.utils.api.ApiCallback
import com.cheyun.netsalev3.utils.api.ApiClient
import com.cheyun.netsalev3.utils.api.ApiException
import com.cheyun.netsalev3.utils.api.BaseResp
import com.google.gson.Gson
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import java.util.*


class AddDriveActivityRepository {
    fun editReservemit(editClueParam: EditDriveParam, moth: (clueDetails: Any) -> Unit, fail:()->Unit) {
        var json = Gson().toJson(editClueParam)
        var map = CommonFunc.gson.fromJson<TreeMap<String, String>>(json, typeToken)
        ApiClient.getInstance().reservemit(map)
                .subscribeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(object : ApiCallback<BaseResp<Any>>() {
                    override fun onSuccess(t: BaseResp<Any>) {
                        t.data?.apply(moth)
                    }
                    override fun onError(ex: ApiException) {
                        fail()
                    }
                })
    }


    fun getTimeList(stime: String,series:String,spec:String,licence:String, moth: (list: List<NormalList>) -> Unit) {
        ApiClient.getInstance().getTimeList(stime,series,spec,licence)
                .subscribeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(object : ApiCallback<BaseResp<List<NormalList>>>() {
                    override fun onSuccess(t: BaseResp<List<NormalList>>) {
                        t.data?.apply(moth)
                    }
                    override fun onError(ex: ApiException) {

                    }
                })
    }

    fun getDriveUsers(moth: (list: List<MemberX>) -> Unit) {
        ApiClient.getInstance().getDriveUsers()
                .subscribeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(object : ApiCallback<BaseResp<List<MemberX>>>() {
                    override fun onSuccess(t: BaseResp<List<MemberX>>) {
                        t.data?.apply(moth)
                    }
                    override fun onError(ex: ApiException) {

                    }
                })
    }


}